package com.example.tliaswebmanagement.controller;

import com.example.tliaswebmanagement.pojo.Emp;
import com.example.tliaswebmanagement.pojo.Login;
import com.example.tliaswebmanagement.pojo.Result;
import com.example.tliaswebmanagement.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {
    private final EmpService empService;

    public LoginController(EmpService empService) {
        this.empService = empService;
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result loginRequest(@RequestBody Emp emp) {
        log.info("前端传递的登录信息为：{}", emp);
        Login login = empService.loginRequest(emp);
        if(login != null) {
            return Result.success(login);
        }
        return Result.error("用户名或密码错误");
    }
}
